﻿#ifndef CLIENTREQUEST_H
#define CLIENTREQUEST_H

#include <clienthandle.h>
#include <QJsonObject>
#include <memory>

class ClientRequest
{
public:
    ClientRequest();
    virtual ~ClientRequest();
    virtual void ProcessRequest(ClientHandle *c, const QJsonObject &obj) = 0;
};

using requestPtr = std::shared_ptr<ClientRequest>;

#define REGISTERCLASS(name) class name:public ClientRequest \
{ \
public: \
    using ClientRequest::ClientRequest; \
    ~name()override{} \
    virtual void ProcessRequest(ClientHandle *c, const QJsonObject &obj)override; \
};

REGISTERCLASS(Login)
REGISTERCLASS(SignUp)
REGISTERCLASS(OnlineList)

class Factory
{
public:
    // 获取单例实例的静态方法
    static Factory *getInstance()
    {
        static Factory instance;
        return &instance;
    }
    Factory();

    requestPtr getProcess(const QString &request);

private:
    std::map<QString, requestPtr> requests;
};


#endif // CLIENTREQUEST_H
